import {
  BaseScene
} from "../object/baseScene";

export class LoadScene extends BaseScene {
  constructor() {
    super('LoadScene')
  }
  // 创建进度条
  _createLoadingBar() {
    this.cameras.main.setBackgroundColor(0xcfe4f5)
    this.loadingBar.fillStyle(0xffffff, 1);
    this.loadingBar.fillRect(
      this.cameras.main.width / 4 - 2,
      this.cameras.main.height / 2 - 18,
      this.cameras.main.width / 2 + 4,
      20
    )
  }
  init() {
    // 加载进度条
    this.loadingBar = this.add.graphics()
    this.progressBar = this.add.graphics()
    this._createLoadingBar()

    // 文本样式
    this.textStyle = {
      fontSize: 36,
      color: '#5555ff',
      fontFamily: '楷体'
    }
  }

  preload() {
    // 预加载
    this.load.image('checkerBoardBg', require('../../assets/checkerBoardBg.png'))
    this.load.image('startBg', require('../../assets/startBg.jpg'))
    this.load.image('pieceBlack', require('../../assets/black.png'))
    this.load.image('pieceWhite', require('../../assets/white.png'))

    this.load.on('progress', (rate) => {
      this.progressBar.clear()
      this.progressBar.fillStyle(0x88e453, 1)
      this.progressBar.fillRect(
        this.cameras.main.width / 4,
        this.cameras.main.height / 2 - 16,
        (this.cameras.main.width / 2) * rate,
        16
      )
    })
    this.load.on('complete', () => {
      this.cameras.main.setBackgroundColor(0xcfe4f5)
      this.loadingBar.destroy()
      this.progressBar.destroy()
      '#000'
    })
  }
  create() {
    this.add.image(this.gameCenterX, this.gameCenterY, 'startBg')

    this.practice = this.add.text(this.computedX(-100), this.computedY(200), '练习模式', this.textStyle)
    this.practice.setInteractive() // 设置 输入检测
    this.practice.on('pointerdown', () => {
      this.scene.switch('PracticeScene') // 保留该场景 并切换至其他场景
    })

    this.onLine = this.add.text(this.computedX(-100), this.computedY(0), '联机大厅', this.textStyle)
    this.onLine.setInteractive() // 设置 输入检测
    this.onLine.on('pointerdown', () => {
      this.game.Vue.onlineRoom()
      // this.scene.switch('OnLineScene') // 保留该场景 并切换至其他场景
    })
    // this.game.Vue.onlineRoom()
    // this.scene.switch('PracticeScene')

    
  }
  update() {

  }
}
